﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
    public class ChuyenTauDAO
    {
        public DataTable DanhSachChuyenTau()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_DanhSachChuyenTau");
            return dt;
        }
        

        public DataTable DanhSachLoaiChuyen()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_DanhSachLoaiChuyen");
            return dt;
        }
        
        public DataTable ThongTinGa()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_ThongTinGa");
            return dt;
        }

        public DataTable TauXeLua()
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            dt = dp.SqlExcuteQuery("sp_TauXeLua");
            return dt;
        }
        
        public void ThemChuyenTau(ChuyenTauDTO _ChuyenTauDto)
        {
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@MaChuyenTau", _ChuyenTauDto.MaChuyenTau));
            para.Add(new SqlParameter("@LoaiChuyen", _ChuyenTauDto.LoaiChuyen));
            para.Add(new SqlParameter("@NgayKhoiHanh", _ChuyenTauDto.NgayKhoiHanh));
            para.Add(new SqlParameter("@MaTau", _ChuyenTauDto.MaTau));
            para.Add(new SqlParameter("@ThongTinGa", _ChuyenTauDto.ThongTinGa));
            dp.SqlExcuteNonQuery("sp_ThemChuyenTau", para.ToArray());
        }

        public void CapNhatChuyenTau(ChuyenTauDTO _ChuyenTauDto)
        {
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@IDChuyenTau", _ChuyenTauDto.IDChuyenTau));
            para.Add(new SqlParameter("@MaChuyenTau", _ChuyenTauDto.MaChuyenTau));
            para.Add(new SqlParameter("@LoaiChuyen", _ChuyenTauDto.LoaiChuyen));
            para.Add(new SqlParameter("@NgayKhoiHanh", _ChuyenTauDto.NgayKhoiHanh));
            para.Add(new SqlParameter("@MaTau", _ChuyenTauDto.MaTau));
            para.Add(new SqlParameter("@ThongTinGa", _ChuyenTauDto.ThongTinGa));
            dp.SqlExcuteNonQuery("sp_CapNhatChuyenTau", para.ToArray());
        }

        public void XoaChuyenTau(ChuyenTauDTO _ChuyenTauDto)
        {
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@IDChuyenTau", _ChuyenTauDto.IDChuyenTau));
            dp.SqlExcuteNonQuery("sp_XoaChuyenTau", para.ToArray());
        }

        public DataTable LayLoaiChuyen(ChuyenTauDTO _ChuyenTauDto)
        {
            DataTable dt = new DataTable();
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@MaLoaiChuyen", _ChuyenTauDto.LoaiChuyen));
            dt = dp.SqlExcuteQuery("sp_LayLoaiChuyen", para.ToArray());
            return dt;
        }

        public DataTable DiaDiemDi(ChuyenTauDTO _ChuyenTauDto)
        {
            DataTable dt = new DataTable();
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@ThongTinGa", _ChuyenTauDto.ThongTinGa));
            dt = dp.SqlExcuteQuery("sp_ThongTinGa_DiaDiem", para.ToArray());

            List<SqlParameter> para1 = new List<SqlParameter>();
            para1.Add(new SqlParameter("@DiaDiemDi", dt.Rows[0]["DiaDiemDi"]));
            return dp.SqlExcuteQuery("sp_LayDiaDiemDi", para1.ToArray());
        }

        public DataTable DiaDiemDen(ChuyenTauDTO _ChuyenTauDto)
        {
            DataTable dt = new DataTable();
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@ThongTinGa", _ChuyenTauDto.ThongTinGa));
            dt = dp.SqlExcuteQuery("sp_ThongTinGa_DiaDiem", para.ToArray());

            List<SqlParameter> para1 = new List<SqlParameter>();
            para1.Add(new SqlParameter("@DiaDiemDen", dt.Rows[0]["DiaDiemDen"]));
            return dp.SqlExcuteQuery("sp_LayDiaDiemDen", para1.ToArray());
        }

        public DataTable TimKiemGaTau(ChuyenTauDTO _ChuyenTauDto)
        {
            DataTable dt = null;
            DataProvider dp = new DataProvider();
            List<SqlParameter> para = new List<SqlParameter>();
            para.Add(new SqlParameter("@MaChuyenTau", _ChuyenTauDto.MaChuyenTau));
            dt = dp.SqlExcuteQuery("sp_TimKiemChuyenTau", para.ToArray());
            return dt;
        }
    }
}
